using System;
using WindowsPhoneMVC.Navigation.Interfaces;

namespace WindowsPhoneMVC.Navigation
{
    public class DefaultControllerFactory : IControllerFactory
    {
        public T Create<T>() where T : Controller
        {
            return Activator.CreateInstance<T>();
        }

        public Controller Create(Type controllerType)
        {
            return (Controller)Activator.CreateInstance(controllerType);
        }

        public void Release(Controller controller)
        {
            var disposible = controller as IDisposable;
            if (disposible != null) disposible.Dispose();
        }
    }
}